package com.example.childrendapp.totalscore;

import java.io.File;
import java.io.FileOutputStream;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.childrendapp.R;

public class AppTotalScore extends Activity implements OnClickListener {
	private TextView mShowTotal;
	private Button mBackMenu, mSaveScore, mCaptureScreen;
	LinearLayout mLinearLayout;
	Bitmap bm;
	private ImageView img;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_app_totalscore);
		mShowTotal = (TextView) findViewById(R.id.show_totalscore);

		mBackMenu = (Button) findViewById(R.id.btn_back_totalscore_to_menu);
		mBackMenu.setOnClickListener(this);

		mSaveScore = (Button) findViewById(R.id.btn_save_to_database);
		mSaveScore.setOnClickListener(this);

		mCaptureScreen = (Button) findViewById(R.id.btn_shot_screen);
		mCaptureScreen.setOnClickListener(this);

		String str = this.getIntent().getExtras().getString("Score");
		mShowTotal.setText(str);
		mLinearLayout=(LinearLayout) findViewById(R.id.linearlayout1);
		img=(ImageView) findViewById(R.id.img);
	
	}

	@Override
	public void onClick(View v) {
		if(v==mCaptureScreen){
			View view =mLinearLayout.getRootView();
			view.setDrawingCacheEnabled(true);
			bm=view.getDrawingCache();
			BitmapDrawable bitmap=new BitmapDrawable(bm);
			img.setBackgroundDrawable(bitmap);
			File file=new File(Environment.getExternalStorageDirectory()+"/nhoinhoi.jpg");
			try {
				file.createNewFile();
				FileOutputStream os=new FileOutputStream(file);
				bm.compress(CompressFormat.JPEG, 100, os);
				os.close();
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		// TODO Auto-generated method stub

	}

}
